from os import listdir
import pdb

class MorgueFile:
    def __init__(self, file_name):
        raw_data = open(file_name, 'r').readlines()
        self.gold = self.gold_count(raw_data)


    def find_line_number(self, data_to_search, string_to_find):
        line_counter = 0
        for line in data_to_search:
            #pdb.set_trace()
            if string_to_find in line:
                return line_counter
                break
            line_counter +=1


    def gold_count(self, data_to_search):
        gold_line = self.find_line_number(data_to_search, 'Gold')
        #pdb.set_trace()
        gold_string = data_to_search[gold_line].rstrip()
        gold_string = gold_string[5:]
        gold_count = int(gold_string.split(' ')[0])
        return gold_count



class Morgue:
    def __init__(self, morgue_directory):
        all_files = listdir(morgue_directory)
        character_list = self.populate_character_list(all_files)


    def populate_character_list(self, all_files):
        character_list = []
        for file_name in all_files:
            if file_name.startswith('morgue') and file_name.endswith('.txt'):
                character_list.append(MorgueFile(file_name))
        return character_list